Skip to content

feat(integration-github): add repository purpose filtering#373

Merged
arthurbazzz merged 4 commits into
4.xfrom
feat/github-repository-purpose
Jun 30, 2026
Merged

feat(integration-github): add repository purpose filtering#373
arthurbazzz merged 4 commits into
4.xfrom
feat/github-repository-purpose

Conversation

@arthurbazzz

Copy link
Copy Markdown
Contributor

Contexto

  • Foi adicionado o campo purpose em github_repositories
  • contributions definido como valor padrão
  • Filtro colocado impedindo que repositórios com purpose = challenge gerem contribuições
  • Mantém o comportamento atual para repositórios com purpose = contributions
  • Adiciona testes para os dois cenários (contributions e challenge)

Closes #344

@arthurbazzz arthurbazzz requested a review from a team June 24, 2026 13:54
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 1001b0b0-8d8a-4e0b-9623-edb9d90ec628

📥 Commits

Reviewing files that changed from the base of the PR and between 80967c2 and 0c619ef.

📒 Files selected for processing (3)
  • app-modules/integration-github/src/Models/GithubRepository.php
  • app-modules/integration-github/src/Webhook/ProjectGithubEvent.php
  • app-modules/integration-github/tests/Feature/GithubWebhookTest.php
🚧 Files skipped from review as they are similar to previous changes (3)
  • app-modules/integration-github/src/Webhook/ProjectGithubEvent.php
  • app-modules/integration-github/src/Models/GithubRepository.php
  • app-modules/integration-github/tests/Feature/GithubWebhookTest.php

📝 Walkthrough

Walkthrough

A new purpose string column is added to github_repositories and backfilled to contributions. PurposeType is introduced as a backed enum, GithubRepository gains a purpose PHPDoc property and enum cast, and the repository factory sets purpose to contributions. ProjectGithubEvent::tenantsTracking() now limits matching repositories to purpose = contributions. Feature tests cover both challenge and contributions repository behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Most requirements are met, but #344 also requires a contributions default for purpose, and the migration only adds a nullable column with backfill. Set the purpose column default to contributions in the migration, then keep the backfill and existing tests.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: filtering integration-github repositories by purpose.
Description check ✅ Passed The description matches the changeset and summarizes the purpose split, filtering, and tests.
Out of Scope Changes check ✅ Passed All changes stay within the repository-purpose split, webhook filtering, and related test coverage.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
app-modules/integration-github/src/Webhook/ProjectGithubEvent.php (1)

59-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Magic string 'contributions' duplicated across migration, query, and tests.

Centralize in a constant or enum to prevent silent drift between the default value and this filter.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app-modules/integration-github/src/Webhook/ProjectGithubEvent.php` at line
59, The `ProjectGithubEvent` query is using the magic string `contributions`
directly, which is duplicated across the codebase and can drift from the default
value. Introduce a shared constant or enum for this purpose value in the
relevant model/event class and use it in `ProjectGithubEvent` instead of the
literal string. Update the migration/default handling and any tests to reference
the same symbol so the filter, default, and assertions stay aligned.
app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php (1)

9-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing down() makes rollback a silent no-op.

Without a down(), migrate:rollback won't drop the purpose column, leaving schema drift.

♻️ Add rollback
     public function up(): void
     {
         Schema::table('github_repositories', static function (Blueprint $table): void {
             $table->string('purpose')->default('contributions');
         });
     }
+
+    public function down(): void
+    {
+        Schema::table('github_repositories', static function (Blueprint $table): void {
+            $table->dropColumn('purpose');
+        });
+    }
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php`
around lines 9 - 17, The migration adds the github_repositories purpose column
in the anonymous Migration class but lacks a rollback path, so implement a
down() method that reverses the change by dropping purpose from the table. Use
the existing up() method and Schema::table pattern in this migration to keep the
forward and rollback behavior aligned.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php`:
- Around line 9-17: The migration adds the github_repositories purpose column in
the anonymous Migration class but lacks a rollback path, so implement a down()
method that reverses the change by dropping purpose from the table. Use the
existing up() method and Schema::table pattern in this migration to keep the
forward and rollback behavior aligned.

In `@app-modules/integration-github/src/Webhook/ProjectGithubEvent.php`:
- Line 59: The `ProjectGithubEvent` query is using the magic string
`contributions` directly, which is duplicated across the codebase and can drift
from the default value. Introduce a shared constant or enum for this purpose
value in the relevant model/event class and use it in `ProjectGithubEvent`
instead of the literal string. Update the migration/default handling and any
tests to reference the same symbol so the filter, default, and assertions stay
aligned.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro

Run ID: aa0e4d01-f06b-45a7-abb5-5bcb14037f64

📥 Commits

Reviewing files that changed from the base of the PR and between ade5d6c and 79d4c0c.

📒 Files selected for processing (4)
  • app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php
  • app-modules/integration-github/src/Models/GithubRepository.php
  • app-modules/integration-github/src/Webhook/ProjectGithubEvent.php
  • app-modules/integration-github/tests/Feature/GithubWebhookTest.php

@danielhe4rt

Copy link
Copy Markdown
Contributor

@Clintonrocha98 @gvieira18

* @property string $tenant_id
* @property string $full_name
* @property bool $enabled
* @property string $purpose

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't 'purpose' be an enum rather than a string here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this but i dunno if the "purpose" will grow more or if will remain only this two (contributions | challenge)

So is it better to create a enum?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is it better to create a enum?

IMO yes, it will prevent the spread of a possible incorrect string in the system, and at the same time, we will keep it as a strong type, specifying that it will always be only one of these values.

Comment on lines +11 to +16
public function up(): void
{
Schema::table('github_repositories', static function (Blueprint $table): void {
$table->string('purpose')->default('contributions');
});
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the idea of implementing an enum for this value, I would use a nullable string rather than a default value. Then, I would add an extra step to fill it with the default values.

Note

Do not use enums in migrations.
This could be impacted by a change in the future.
It will not be implemented if migration has already occurred; it will only be implemented on new databases.

Suggested change
public function up(): void
{
Schema::table('github_repositories', static function (Blueprint $table): void {
$table->string('purpose')->default('contributions');
});
}
public function up(): void
{
Schema::table('github_repositories', static function (Blueprint $table): void {
$table->string('purpose')->nullable();
});
DB::table('github_repositories')
->update(['purpose' => 'contributions']);
}

Before applying/implementing this suggestion, I would like to hear from @danielhe4rt and @Clintonrocha98. Default values aren't a problem, but they could be in the future.

@Clintonrocha98 Clintonrocha98 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two suggestions around the new purpose enum: adding the matching cast on the model, and using the enum directly in the query.

* @property string $tenant_id
* @property string $full_name
* @property bool $enabled
* @property PurposeType $purpose

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PHPDoc already declares @property PurposeType $purpose, but casts() has no matching cast. At runtime $repo->purpose still returns a string, so the PHPDoc doesn't reflect the actual type. To align it, following @gvieira18's idea of keeping it as an enum:

protected function casts(): array
{
    return [
        'enabled' => 'boolean',
        'last_backfilled_at' => 'datetime',
        'purpose' => PurposeType::class,
    ];
}

This makes the attribute strongly typed and keeps the PHPDoc honest about the real behavior.

return array_values(GithubRepository::query()
->enabled()
->where('full_name', $repo)
->where('purpose', PurposeType::Contributions->value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor readability improvement tied to the cast on the model: the query builder accepts a BackedEnum directly (it resolves ->value via enum_value()), so this can be simplified to:

Suggested change
->where('purpose', PurposeType::Contributions->value)
->where('purpose', PurposeType::Contributions)

The generated SQL is identical, this just drops the ->value.

@cherryramatisdev

Copy link
Copy Markdown

considering the above comments are fixed, lgtm :D

@arthurbazzz arthurbazzz merged commit 3d858d4 into 4.x Jun 30, 2026
6 checks passed
@arthurbazzz arthurbazzz deleted the feat/github-repository-purpose branch June 30, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(integration-github): GithubRepository.purpose + excluir challenge das contribuições

5 participants